export function treeToFlat(
	target,
	subsetKey = "children"
) {
	const copyTree =
		Object.prototype.toString.call(target) === "[object Array]"
			? Array.prototype.slice.call(target)
			: [target];

	const flat = [];

	while (copyTree.length) {
		const node = copyTree.shift();
		const { [subsetKey]: children, ...rest } = node;
		flat.push(rest);
		if (children) {
			Array.prototype.push.apply(copyTree, node.children);
		}
	}

	return flat;
}
